﻿<common:LayoutAwarePage
    x:Name="pageRoot"
    x:Class="LeapSample.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:LeapSample"
    xmlns:common="using:LeapSample.Common"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d"
    d:DataContext="{d:DesignInstance Type=local:SampleViewModel, IsDesignTimeCreatable=true}">
    <common:LayoutAwarePage.Resources>
        <common:SameToVisibilityConverter x:Key="SameToVisibilityConverter"/>
    </common:LayoutAwarePage.Resources>

    <!--
        This grid acts as a root panel for the page that defines two rows:
        * Row 0 contains the back button and page title
        * Row 1 contains the rest of the page layout
    -->
    <Grid Style="{StaticResource LayoutRootStyle}">
        <Grid.RowDefinitions>
            <RowDefinition Height="140"/>
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>

        <!-- Back button and page title -->

        <Grid>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="Auto"/>
                <ColumnDefinition Width="*"/>
            </Grid.ColumnDefinitions>
            <Button x:Name="backButton" Click="GoBack" IsEnabled="{Binding Frame.CanGoBack, ElementName=pageRoot}" Style="{StaticResource BackButtonStyle}"/>
            <TextBlock x:Name="pageTitle" Grid.Column="1" Text="LeapSample" Style="{StaticResource PageHeaderTextStyle}"/>
        </Grid>
        <Grid Grid.Row="1">
            <Grid.ColumnDefinitions>
                <ColumnDefinition/>
                <ColumnDefinition/>
            </Grid.ColumnDefinitions>
            <TextBlock HorizontalAlignment="Center" TextWrapping="Wrap" Text="{Binding Item.FingerCount}" VerticalAlignment="Center" FontSize="96"/>
            <Image HorizontalAlignment="Center" Height="200" VerticalAlignment="Center" Width="200" Grid.Column="1" Source="ms-appx:///Assets/janken-01.png" Visibility="{Binding Item.FingerCount, ConverterParameter=0, Converter={StaticResource SameToVisibilityConverter}}"/>
            <Image HorizontalAlignment="Center" Height="200" VerticalAlignment="Center" Width="200" Grid.Column="1" Source="ms-appx:///Assets/janken-02.png" Visibility="{Binding Item.FingerCount, ConverterParameter=2, Converter={StaticResource SameToVisibilityConverter}}"/>
            <Image HorizontalAlignment="Center" Height="200" VerticalAlignment="Center" Width="200" Grid.Column="1" Source="ms-appx:///Assets/janken-03.png" Visibility="{Binding Item.FingerCount, ConverterParameter=5, Converter={StaticResource SameToVisibilityConverter}}"/>
        </Grid>

        <VisualStateManager.VisualStateGroups>
            <!-- Visual states reflect the application's view state -->
            <VisualStateGroup x:Name="ApplicationViewStates">
                <VisualState x:Name="FullScreenLandscape"/>
                <VisualState x:Name="Filled"/>

                <!-- The entire page respects the narrower 100-pixel margin convention for portrait -->
                <VisualState x:Name="FullScreenPortrait">
                    <Storyboard>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="backButton" Storyboard.TargetProperty="Style">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource PortraitBackButtonStyle}"/>
                        </ObjectAnimationUsingKeyFrames>
                    </Storyboard>
                </VisualState>

                <!-- The back button and title have different styles when snapped -->
                <VisualState x:Name="Snapped">
                    <Storyboard>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="backButton" Storyboard.TargetProperty="Style">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource SnappedBackButtonStyle}"/>
                        </ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="pageTitle" Storyboard.TargetProperty="Style">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource SnappedPageHeaderTextStyle}"/>
                        </ObjectAnimationUsingKeyFrames>
                    </Storyboard>
                </VisualState>
            </VisualStateGroup>
        </VisualStateManager.VisualStateGroups>
    </Grid>
</common:LayoutAwarePage>
